package gunfire.actions;

import basemod.cardmods.ExhaustMod;
import basemod.helpers.CardModifierManager;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.MakeTempCardInHandAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import gunfire.GunfireMod;

public class CuriosityBoxAction extends AbstractGameAction {
    private final AbstractPlayer p;
    private static final float DURATION;
    private final boolean upgraded;

    public CuriosityBoxAction(boolean upgraded) {
        this.actionType = ActionType.CARD_MANIPULATION;
        this.duration = DURATION;
        this.p = AbstractDungeon.player;
        this.upgraded = upgraded;
    }

    public void update() {
        if (this.duration == DURATION) {
            if (this.p.hand.isEmpty()) {
                this.isDone = true;
            } else if (this.p.hand.size() == 1) {
                AbstractCard c = this.p.hand.getBottomCard().makeStatEquivalentCopy();
                if (c.type != AbstractCard.CardType.POWER) {
                    CardModifierManager.addModifier(c, new ExhaustMod());
                }
                this.addToBot(new MakeTempCardInHandAction(c, 1));
                this.isDone = true;
            } else {
                AbstractDungeon.handCardSelectScreen.open(Settings.language == Settings.GameLanguage.ZHS ? "复制" : "Copy", 1, false, false);
                this.tickDuration();
            }
        } else {
            if (!AbstractDungeon.handCardSelectScreen.wereCardsRetrieved) {
                AbstractCard tmpCard = AbstractDungeon.handCardSelectScreen.selectedCards.getBottomCard();
                AbstractCard c = tmpCard.makeStatEquivalentCopy();
                if (c.type != AbstractCard.CardType.POWER) {
                    CardModifierManager.addModifier(c, new ExhaustMod());
                }
                this.addToBot(new MakeTempCardInHandAction(c, 1));
                AbstractDungeon.player.hand.addToHand(tmpCard);
                AbstractDungeon.handCardSelectScreen.selectedCards.clear();
                AbstractDungeon.handCardSelectScreen.wereCardsRetrieved = true;
            }

            this.tickDuration();
        }
    }

    static {
        DURATION = Settings.ACTION_DUR_XFAST;
    }
}
